package database

import (
	"dawncloud/config"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

var viper = config.LoadConfig()

func ConnectDB() *gorm.DB {
	dsn := viper.GetString("database.user") + ":" +
		viper.GetString("database.password") + "@tcp(" +
		viper.GetString("database.host") + ":" +
		viper.GetString("database.port") + ")/" +
		viper.GetString("database.dbname") + "?charset=utf8mb4&parseTime=True&loc=Local"
	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	return db
}
